
<%@ page import="com.auctionhaus.Listing" %>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <meta name="layout" content="main" />
        <g:set var="entityName" value="${message(code: 'listing.label', default: 'Listing')}" />
        <title><g:message code="default.show.label" args="[entityName]" /></title>
    </head>
    <body>
        <g:render template="/layouts/menuBar" />
        <div class="body">
            <h1><g:message code="default.show.label" args="[entityName]" /></h1>
            <g:if test="${flash.message}">
            <div class="message">${flash.message}</div>
            </g:if>
            <div class="dialog">
                <table>
                    <tbody>
                        <tr class="prop">
                            <th valign="top" class="name"><g:message code="listing.id.label" default="Id" /></th>
                            <th valign="top" class="name"><g:message code="listing.listName.label" default="List Name" /></th>
                            <th valign="top" class="name"><g:message code="listing.creationDate.label" default="Creation Date" /></th>
                            <th valign="top" class="name"><g:message code="listing.description.label" default="Description" /></th>
                            <th valign="top" class="name"><g:message code="listing.startBidPrice.label" default="Starting Bid Price" /></th>
                            <th valign="top" class="name"><g:message code="listing.currentBidPrice.label" default="Current Bid Price" /></th>
                            <th valign="top" class="name"><g:message code="listing.seller.emailAddress.label" default="Seller" /></th>
                            <th valign="top" class="name"><g:message code="listing.endDateTime.label" default="End Date Time" /></th>
                            <th valign="top" class="name"><g:message code="listing.numberOfBids.label" default="Number Of Bids" /></th>
                        </tr>
                        <tr>
                            <td valign="top" class="value">${fieldValue(bean: listingInstance, field: "id")}</td>
                            <td valign="top" class="value">${fieldValue(bean: listingInstance, field: "listName")}</td>
                            <td valign="top" class="value">${fieldValue(bean: listingInstance, field: "creationDate")}</td>
                            <td valign="top" class="value">${fieldValue(bean: listingInstance, field: "description")}</td>
                            <td valign="top" class="value">${fieldValue(bean: listingInstance, field: "startBidPrice")}</td>
                            <td valign="top" class="value">${listingInstance.getMaxBidPrice()}</td>
                            <td><g:link controller="customer" action="show" id="${listingInstance.seller.id}">${listingInstance.seller.getLoginName()}</g:link></td>
                            <td valign="top" class="value">${fieldValue(bean: listingInstance, field: "endDateTime")}</td>
                            <td valign="top" class="value">${listingInstance.getNumberOfBids()}</td>

                        </tr>
                    </tbody>
                </table>
            </div>
            <div class="buttons">
                <g:form>
                    <g:hiddenField name="id" value="${listingInstance?.id}" />
                    <span class="button"><g:actionSubmit class="edit" action="edit" value="${message(code: 'default.button.edit.label', default: 'Edit')}" /></span>
                    <span class="button"><g:actionSubmit class="delete" action="delete" value="${message(code: 'default.button.delete.label', default: 'Delete')}" onclick="return confirm('${message(code: 'default.button.delete.confirm.message', default: 'Are you sure?')}');" /></span>
                </g:form>
            </div>
            <div>
                <g:set var="bidEntity" value="${message(code: 'bid.label', default: 'Bid')}" />
                <g:set var="bidDescription" value="${message(code: 'bid.winning.label', default: 'Winning')}" />

                <div>
                    <table>
                        <h1><g:message code="default.show.descriptive.label" args="[bidDescription, bidEntity]" /></h1>
                        <tbody>
                            <tr class="prop">
                                <th valign="top" class="name"><g:message code="bid.id.label" default="Id" /></th>
                                <th valign="top" class="name"><g:message code="bid.amount.label" default="Bid Amount" /></th>
                                <th valign="top" class="name"><g:message code="bid.date.label" default="Bid Date Time" /></th>
                                <th valign="top" class="name"><g:message code="bid.buyer.emailAddress.label" default="Buyer" /></th>
                                <th valign="top" class="name"><g:message code="bid.listing.listName.label" default="Listing" /></th>
                            </tr>
                            <tr>
                                <td valign="top" class="value">${fieldValue(bean: listingInstance.getMaxBid(), field: "id")}</td>
                                <td valign="top" class="value">${fieldValue(bean: listingInstance.getMaxBid(), field: "amount")}</td>
                                <td valign="top" class="value">${fieldValue(bean: listingInstance.getMaxBid(), field: "date")}</td>
                                <g:if test="${listingInstance?.getMaxBid()}">
                                    <td><g:link controller="customer" action="show" id="${listingInstance?.getMaxBid()?.buyer.id}">${fieldValue(bean: listingInstance?.getMaxBid(), field: "buyer.emailAddress")}</g:link></td>
                                     <td valign="top" class="value">${fieldValue(bean: listingInstance.getMaxBid(), field: "listing.listName")}</td>
                                </g:if>
                                <g:else>
                                     <td valign="top" class="value"></td>
                                     <td valign="top" class="value"></td>
                                </g:else>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
            <g:if test="${listingInstance?.endDateTime > new Date()}">
                <div>
                    <g:set var="newBidEntity" value="${message(code: 'bid.label', default: 'Bid')}" />
                    <g:form name="myBidForm" controller="bid" action="save">
                        <table>
                           <h1  align="right"><g:message code="default.place.descriptive.label" args="[newBidEntity]" /></h1>
                                <div class="formField" align="right">
                                  <label for="amount">Bid Amount:</label>
                                  <g:textField name="amount" value="${myBidEntity?.amount}" />
                                </div>
                                <div class="formField" align="right">
                                    <label for="buyerEmailAddress">Buyer Email Address:</label>
                                    <g:textField name="buyerEmailAddress" value="${myBidEntity?.buyer?.emailAddress}"/>
                                </div>
                                <g:hiddenField name="selectedListName" value="${listingInstance.listName}" />
                                <div class="button" align="right"><g:submitButton name="save" class="save" value="${message(code: 'default.new.label', default: 'New', args:[newBidEntity])}" /></div>
                        </table>
                    </g:form>
                </div>
            </g:if>
        </div>
    </body>
</html>
